package com.cs.beneficios.web.action;
import com.cs.beneficios.business.entity.AtributosDAO;
import com.cs.beneficios.business.entity.RepBeneficioOtorgadoDAO;
import com.cs.beneficios.business.entity.RestriccionDAO;
import com.cs.beneficios.business.model.AtributoVO;
import com.cs.beneficios.business.model.RestriccionVO;
import com.cs.beneficios.common.ConnectionFactory;
import java.sql.SQLException;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
//import org.apache.struts.action.ActionError;
//import org.apache.struts.action.ActionErrors;
import java.io.IOException;
import javax.servlet.ServletException;

public class ModificarRestricAction extends Action 
{
  /**
   * This is the main action called from the Struts framework.
   * @param mapping The ActionMapping used to select this instance.
   * @param form The optional ActionForm bean for this request.
   * @param request The HTTP Request we are processing.
   * @param response The HTTP Response we are processing.
   * @return 
   * @throws java.io.IOException
   * @throws javax.servlet.ServletException
   */
  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  {
     HttpSession session = request.getSession();
     String sub = (String)session.getAttribute("subpro");
     session.setAttribute("subprograma",sub);
     session.removeAttribute("listavfl");
     String strCodAtri = request.getParameter("codatributo");
     session.setAttribute("codatributo",strCodAtri);
     
     //ConnectionFactory cf = new ConnectionFactory("beneficios","beneficios");
	 ConnectionFactory cf = new ConnectionFactory();
     AtributosDAO atriDAO = new AtributosDAO(cf);
     AtributoVO objAtributoVO = new AtributoVO();
     Collection cAtributos = null;  
     try
     {
       objAtributoVO = atriDAO.GetPropiedadesAtri(strCodAtri);
       cf.closeConnection(atriDAO.getConn());
       //Proceso para saber si el atributo tiene lista de valores
       RepBeneficioOtorgadoDAO objBeneOtorDAO = new RepBeneficioOtorgadoDAO(cf);
       List coListas = new LinkedList();
       coListas = (List)objBeneOtorDAO.getListaAtri(strCodAtri);
       cf.closeConnection(objBeneOtorDAO.getConn());
       if(coListas.size()>0)
       {
         session.setAttribute("listavfl",coListas);
       }
       //Fin del proceso
       
       //proceso para obtener la informacion de la restriccion
       String strCodRest = objAtributoVO.getRestriccion();
       session.setAttribute("codrestric",strCodRest);
       RestriccionDAO objRestDAO = new RestriccionDAO(cf);
       RestriccionVO objRestVO = objRestDAO.getRestriccion(strCodRest);
       cf.closeConnection(objRestDAO.getConn());
       session.setAttribute("PropiedadesRestri",objRestVO);
       
       
       String tipodato = objAtributoVO.getTipodato();
       String nombre = objAtributoVO.getNombre();
       session.setAttribute("tipodato",tipodato);
       session.setAttribute("nombre",nombre);
       
       
     }catch(SQLException e){
		System.err.println("/******** TDSUB - cwsub");
		e.printStackTrace();
		System.err.println("TDSSPE - cwsub ********/");
     }
    
    return mapping.findForward("success");
  }
}